import requests

class ApiClient:
    def __init__(self,base_url):
        self.base_url=base_url.rstrip('/')
        self.session = requests.Session()
        self.session.headers = {'Content-Type':'application/json'}

    def url(self,path):
        return f'{self.base_url}/{path.lstrip("/")}'

    def get(self,path,params=None,headers=None):
        return self.session.get(self.url(path),params=params,headers=headers)

    def post(self,path,data=None,json_data=None,headers=None):
        kwargs = {'json':json_data} if json_data else {'data':data}
        return self.session.post(self.url(path),headers=headers,**kwargs)

    def delete(self,path,params=None,headers=None):
        return self.session.delete(self.url(path),headers=headers)


    def put(self,path,data=None,json_data=None,headers=None):
        kwargs = {'json':json_data} if json_data else {'data':data}
        return self.session.put(self.url(path),headers=headers,**kwargs)